package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.business.service.ProductService;
import com.goods.common.model.business.InStock;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/business/inStock")
public class InStockController {

    @Resource
    private InStockService inStockService;

    @Resource
    private ProductService productService;

    //查询入库分页列表
    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(Integer pageNum, Integer pageSize, Integer status,
                                        Integer type, String inNum, String startTime, String endTime){
        Map map = inStockService.findInStockList(pageNum,pageSize,status,type,inNum,startTime,endTime);
        return ResponseBean.success(map);
    }

    //查看入库单明细
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id,Integer pageNum){
        InStockDetailVO inStockDetailVO = inStockService.detail(id);
        return ResponseBean.success(inStockDetailVO);
    }

    //移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        int i = inStockService.remove(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("移入回收站失败");
        }
    }

    //移出回收站
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        int i = inStockService.back(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("移出回收站失败");
        }
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        int i = inStockService.delete(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("删除失败");
        }
    }

    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody Map map){
        inStockService.addIntoStock(map);
        return ResponseBean.success();
    }

    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        int i = inStockService.publish(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("审核失败");
        }
    }

}
